package com.cmz.common.utils;

import com.google.common.collect.Maps;

import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;

/**
 * @author cmz
 * @date 2020/2/19 08:25
 */
public class FeatureUtils {
    public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
        Map<Object, Boolean> map = Maps.newConcurrentMap();
        return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
